home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / stat / RCS / stat.c,v < prev   
Encoding:
Text File  |  1989-09-14  |  2.2 KB  |  102 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.09.13.20.49.03;  author ouster;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * stat.c --
  27.  *
  28.  *    This program is a stand-alone benchmark that measures
  29.  *    the cost of stat-ing a file.
  30.  *
  31.  *    stat fileName count
  32.  *
  33.  *    where "fileName" is the name of the file to stat and
  34.  *    close and "count" tells how many stats to execute.
  35.  *
  36.  * Copyright 1989 Regents of the University of California.
  37.  * Permission to use, copy, modify, and distribute this
  38.  * software and its documentation for any purpose and without
  39.  * fee is hereby granted, provided that the above copyright
  40.  * notice appear in all copies.  The University of California
  41.  * makes no representations about the suitability of this
  42.  * software for any purpose.  It is provided "as is" without
  43.  * express or implied warranty.
  44.  */
  45.  
  46. #ifndef lint
  47. static char rcsid[] = "$Header: protoPub.c,v 1.3 87/01/04 17:28:56 andrew Exp $ SPRITE (Berkeley)";
  48. #endif not lint
  49.  
  50.  
  51. #include <stdio.h>
  52. #include <sys/types.h>
  53. #include <sys/stat.h>
  54. #include <sys/time.h>
  55. #include <sys/resource.h>
  56.  
  57. main(argc, argv)
  58. int argc;
  59. char **argv;
  60. {
  61.     struct stat buf;
  62.     int repeats, fd, count;
  63.     double msPer, micros;
  64.     struct rusage begin ,end;
  65.     struct timeval start, stop;
  66.     struct timezone tz;
  67.  
  68.     if (argc != 3) {
  69.     fprintf(stderr, "Usage:  %s fileName count\n",
  70.         argv[0]);
  71.     exit(1);
  72.     }
  73.     repeats = atoi(argv[2]);
  74.  
  75. #ifdef GETRUSAGE
  76.     getrusage(RUSAGE_SELF, &begin);
  77. #else
  78.     gettimeofday(&start, (struct timezone *) NULL);
  79. #endif
  80.  
  81.     for (count = 0 ; count < repeats; count++) {
  82.     if (stat(argv[1], &buf) != 0) {
  83.         fprintf(stderr, "Couldn't stat %s.\n", argv[1]);
  84.         exit(1);
  85.     }
  86.     }
  87. #ifdef GETRUSAGE
  88.     getrusage(RUSAGE_SELF, &end);
  89.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  90.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  91.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  92.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  93. #else
  94.     gettimeofday(&stop, (struct timezone *) NULL);
  95.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  96.         + stop.tv_usec - start.tv_usec;
  97. #endif
  98.     msPer = (micros/repeats/1000.0);
  99.     printf("Time per stat: %.2f milliseconds\n", msPer);
  100. }
  101. @
  102.